/**
 * 时间的显示样式
 * 0 xx时xx分xx秒   1 xx:xx:xx: 
 */
export enum TimeDisplayType {
    FONT,
    POINT,
}
const TEXT = {
    en: {
        d: 'd', h: 'h', m: 'm', s: 's'
    },

    zh: {
        d: '天', h: '时', m: '分', s: '秒'
    }

}


export class TimeDisplay {

    private static temp: string[] = []

    static getFontString(t: number, lang: string = 'zh') {
        t = Math.floor(t)
        return this.getTimeString(t, TimeDisplayType.FONT, lang)
    }

    static getPointString(t: number, lang: string = 'zh') {
        t = Math.floor(t)
        return this.getTimeString(t, TimeDisplayType.POINT, lang)
    }

    /**
     * 
     * @param t 时间 秒
     * @param type 时间的显示类型 0 xx时xx分xx秒   1 xx:xx:xx: 
     */
    private static getTimeString(t: number, type: TimeDisplayType = TimeDisplayType.FONT, lang: string = 'zh'): string {
        if (!t || t === 0) {
            return "00";
        }
        this.temp.length = 0;
        let time = t;
        // cc.log(" time ",this.time);
        let display: string = "";

        let s = time % 60;

        let m = Math.floor(time / 60 % 60);

        let h = Math.floor(time / 3600 % 24);

        let d = Math.floor(time / 3600 / 24);

        let ss: string = "";
        if (s < 10) {
            ss = "0" + s;
        } else {
            ss = "" + s;
        }
        let mm = '';
        if (m < 10) {
            mm = "0" + m;
        } else {
            mm = "" + m;
        }

        let hh = "";
        if (h < 10) {
            hh = "0" + h;
        } else {
            hh = "" + h;
        }
        let dName = TEXT[lang]["d"]
        let hName = TEXT[lang]["h"]
        let mName = TEXT[lang]["m"]
        let sName = TEXT[lang]["s"]

        if (d > 0) {
            display = `${d}${dName}${hh}${hName}${mm}${mName}`
        } else {
            if (type == TimeDisplayType.FONT) {
                if (h != 0) {
                    display = `${hh}${hName}${mm}${mName}${ss}${sName}`
                } else if (m != 0) {
                    display = `${mm}${mName}${ss}${sName}`
                } else {
                    display = `${ss}${sName}`
                }
            } else {
                if (h != 0) {
                    display = `${hh}:${mm}:${ss}`
                } else if (m != 0) {
                    display = `${mm}:${ss}`
                } else {
                    display = `${ss}`
                }
            }


        }
        return display;
    }
}